using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using CID.Domain.Persistence;
using CID.Web.Support;
using CID.Web.Support.TemplateContentEdition;
using NailsFramework.Config;
using NailsFramework.UserInterface;
using CID.Web.Support.Configuration;
using System.Configuration;

namespace CID.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : NailsMvcApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
            ModelMetadataProviders.Current = new InterfaceCrawlerMetadataProvider();
            ConfigureApplication();
        }

        protected override void ConfigureNails(INailsConfigurator nails)
        {
            nails.IoC.Container<NailsFramework.IoC.Unity>()
                    .Persistence.DataMapper<NailsFramework.Persistence.NHibernate>(CID.Domain.Persistence.Configuration.Configure)
                    .UserInterface.Platform<NailsFramework.UserInterface.Mvc>()
                    .Logging.Logger<NailsFramework.Logging.Log4net>()
                    .InspectAssembly(@"bin\CID.Domain.dll")
                    .InspectAssembly(@"bin\CID.Web.dll")
                    .Initialize();
        }

        private void ConfigureApplication()
        {
            ApplicationConfiguration configuration = (ApplicationConfiguration) ConfigurationManager.GetSection(ApplicationConfiguration.SectionName);
            configuration.TemplateContentEdition.Configure(TemplateContentEditorRegistry.Instance);
        }
    }
}